package com.gxa.service.points.impl;

import com.gxa.dto.pointsdto.IntegrationDto;
import com.gxa.dto.pointsdto.UserDto;
import com.gxa.entity.community.UserList;
import com.gxa.entity.points.IntegralType;
import com.gxa.entity.points.Integration;
import com.gxa.mapper.community.UserListMapper;
import com.gxa.mapper.points.IntegrationMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.service.points.IntegralTypeService;
import com.gxa.service.points.IntegrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yjl
 * @since 2022-10-17 10:36:07
 */
@Service
public class IntegrationServiceImpl extends ServiceImpl<IntegrationMapper, Integration> implements IntegrationService {
    @Autowired
    private IntegrationMapper integrationMapper;

    @Autowired
    private UserListMapper userListMapper;

    @Autowired
    private IntegralTypeService integralTypeService;


    @Override
    public void add(Integer id, String name) {
        long l = System.currentTimeMillis();
        Date date = new Date(l);
        UserDto userdto = this.integrationMapper.queryByName(name);
        IntegrationDto integrationDto = this.integrationMapper.queryByUserName(userdto.getUserNumber());
        Integration integration = new Integration();
        IntegralType integralType = this.integralTypeService.quertById(id);
        if (integrationDto == null){

            integration.setUserNumber(userdto.getUserNumber());
            long time  = date.getTime();
            integration.setCreateTime(date);
            this.integrationMapper.add(integration);
        }else{
            System.out.println(integrationDto);
            integrationDto.setTypeName(integralType.getTypeName());
            integrationDto.setTypeValue(integralType.getTypeValue());
            this.integrationMapper.updateByuserName(integrationDto);
        }
    }

    @Override
    public List<UserDto> queryAll() {
        List<UserDto> userDtos = this.integrationMapper.queryAll();
        return  userDtos;
    }

}
